package com.dcjt.firehotcarpad.utils;

import android.content.Context;
import android.content.DialogInterface;

import androidx.appcompat.app.AlertDialog;


public class AlertViewUtil {

    public static AlertDialog show(Context context, int message, int right) {
        return show(context, 0, message, 0, right, null);
    }

    public static AlertDialog show(Context context, String message, String right) {
        return show(context, "", message, "", right, null);
    }

    public static AlertDialog show(Context context, String title, String message, String right) {
        return show(context, title, message, "", right, null);
    }

    public static AlertDialog show(Context context, int title, int message, int right) {
        return show(context, title, message, 0, right, null);
    }

    public static AlertDialog show(Context context, int message, int right, DialogInterface.OnClickListener listener) {
        return show(context, 0, message, 0, right, listener);
    }

    public static AlertDialog show(Context context, String message, String right, DialogInterface.OnClickListener listener) {
        AlertDialog show = show(context, "", message, "", right, listener);
        return show;
    }

    public static AlertDialog show(Context context, int message, int left, int right, DialogInterface.OnClickListener listener) {
        return show(context, 0, message, left, right, listener);
    }

    public static AlertDialog show(Context context, String message, String left, String right, DialogInterface.OnClickListener listener) {
        return show(context, "", message, left, right, listener);
    }


    public static AlertDialog show(Context context, int title, int message, int left, int right, DialogInterface.OnClickListener listener) {
        AlertDialog.Builder alert = getAlertView(context);
        AlertDialog dialog;
        if (title != 0) {
            alert.setTitle(title);
        }
        if (message != 0) {
            alert.setMessage(message);
        }
        if (left != 0) {
            alert.setNegativeButton(left, listener);
        }
        if (right != 0) {
            alert.setPositiveButton(right, listener);
        }
        dialog = alert.create();
        dialog.show();
        return dialog;
    }
    public static AlertDialog show(Context context, int title, String message, int left, int right, DialogInterface.OnClickListener listener) {
        AlertDialog.Builder alert = getAlertView(context);
        AlertDialog dialog;
        if (title != 0) {
            alert.setTitle(title);
        }
        if (message != null) {
            alert.setMessage(message);
        }
        if (left != 0) {
            alert.setNegativeButton(left, listener);
        }
        if (right != 0) {
            alert.setPositiveButton(right, listener);
        }
        dialog = alert.create();
        dialog.show();
        return dialog;
    }

    public static AlertDialog show(Context context, String title, String message, String left, String right, DialogInterface.OnClickListener listener) {
        AlertDialog.Builder alert = getAlertView(context);
        AlertDialog dialog;
        if (!StringUtils.isEmpty(title)) {
            alert.setTitle(title);
        }
        if (!StringUtils.isEmpty(message)) {
            alert.setMessage(message);
        }
        if (!StringUtils.isEmpty(left)) {
            alert.setNegativeButton(left, listener);
        }

        if (!StringUtils.isEmpty(right)) {
            alert.setPositiveButton(right, listener);
        }
        dialog = alert.create();
        dialog.show();
        return dialog;
    }

    public static AlertDialog.Builder getAlertView(Context context) {
        return new AlertDialog.Builder(context);
    }
}
